/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2020-03-24 15:44
 */
package com.yao.home;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * 多数据源配置
 * 
 * @author yaoyuming
 * @date 2020/03/24 15:44
 */
//@Configuration
public class DataSourceConfig {


    @Bean(name = "finDSProperties")
    @ConditionalOnProperty(name = "spring.datasource.fin.enable", havingValue = "true", matchIfMissing = false)
    public DataSourceProperties ds1DataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean(name = "finDS")
    public DataSource ds1DataSource(@Qualifier("finDSProperties") DataSourceProperties dataSourceProperties) {
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }


    @Bean(name = "authDSProperties")
    @ConfigurationProperties(prefix = "spring.datasource.auth")
    public DataSourceProperties ds2DataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean(name = "authDS")
    public DataSource ds2DataSource(@Qualifier("authDSProperties") DataSourceProperties dataSourceProperties) {
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }


    @Bean(name = "roDSProperties")
    @ConfigurationProperties(prefix = "spring.datasource.ro")
    public DataSourceProperties ds3DataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean(name = "roDS")
    public DataSource ds3DataSource(@Qualifier("roDSProperties") DataSourceProperties dataSourceProperties) {
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }
}